package com.jh.wdbc.service;

import com.nhncorp.dbpropmanager.anttask.RemoteDBPropertiesGetter;
import com.nhncorp.dbpropmanager.model.GlobalConfig;
import com.nhncorp.dbpropmanager.model.PropertyModel;

public class DBPMUtil {
	public static PropertyModel getDBProperty(String phase, String dbid) throws Exception {
		GlobalConfig.setServerDomain(getServerUrl(phase));
		String[] dbids = dbid.split("\\.");
		StringBuilder sb = new StringBuilder(dbids[1]);
		for (int i = 2; i < dbids.length; i++) {
			sb.append(".").append(dbids[i]);
		}

		return RemoteDBPropertiesGetter.getDataSourceProperty(dbids[0], sb.toString());
	}

	private static String getServerUrl(String phase) {
		if ("real".equals(phase)) {
			return "dbpropmanager.admin.nhncorp.com";
		} else {
			return phase + "-dbpropmanager.admin.nhncorp.com";
		}
	}
	
	public static String getDBType(String driver){
		if(driver.contains("Oracle")){
			return "Oracle";
		}
		if(driver.contains("mysql")){
			return "mysql";
		}
		return "others";
	}
}
